<?php

namespace Gql\Contracts;

use GraphQL\Type\Definition\InputType;
use GraphQL\Type\Definition\LeafType;
use GraphQL\Type\Definition\NamedType;
use GraphQL\Type\Definition\OutputType;
use GraphQL\Type\Definition\Type;

abstract class TypeAbstract extends Type implements OutputType, InputType, LeafType, NamedType
{
    protected static $type;
    public $config = [];
    const KEY = 'Key';
    const IMG = 'Img';
    const MIXED = 'Mixed';
    const SERIALIZE = 'serialize';
    const PARSE_VALUE = 'parseValue';
    const PARSE_LITERAL = 'parseLiteral';

    public static function create(array $config = []): array
    {
        $type = self::getInstance($config);
        return array_merge($type->config, [
            self::SERIALIZE => [$type, self::SERIALIZE],
            self::PARSE_VALUE => [$type, self::PARSE_LITERAL],
            self::PARSE_LITERAL => [$type, self::PARSE_LITERAL],
        ]);
    }

    protected static function getInstance(array $config = []): self
    {
        $type=self::$type ?? new static();
        $type->config = $config;
        return $type;
    }

}